home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 5 / Amoszine 5.adf / arts / int2.asc.cm / int2.asc.cm
Text File  |  1992-02-26  |  6KB  |  130 lines

  1. @6                         Understanding the Interface
  2. @5                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3.     Part 2 - BUTTONS
  4.     ~~~~~~
  5. @4
  6.     In the first part, you learned how to open a resource screen and
  7.     display the images from it to create a box.  We now need to turn
  8.     this solitary box into a working requester.  For this, you need
  9.     to know how to output text to the screen in the interface program
  10.     and how to create a button.  Firstly we shall write some text
  11.     into the box.  The interface instruction to do this is called
  12.     PRint.  Here is an example of its use:
  13. @3
  14.     a$=a$+"PRint 10,10,'Click me!!!!',7;"
  15. @4
  16.     The first two parameters that PRint needs are the X and Y
  17.     coordinates.  Next the actual message you wish to display is
  18.     enclosed within SINGLE quotes followed by the pen colour which I
  19.     decided would be 7 ended with a semicolon.  Don't forget the
  20.     semicolon!  That's there all is to it!  Nice and simple, so far.
  21.     Insert that line of code into your interface program and try it
  22.     out.
  23.  
  24.     Next, we need to set up a clickable area for a button plus we
  25.     need to actually draw the button.  First you shall see how to
  26.     unpack a single image from the resource bank.  We are going to
  27.     be using image number 13 and 14 which are the images for an
  28.     untouched button and a clicked button respectively.  The
  29.     interface instruction to unpack an image is unsurprisingly UNpack
  30.     which takes 3 parameters.  Here's how to use it:
  31. @3
  32.     a$=a$+"UNpack 100,20,13;"
  33. @4
  34.     The parameters are (in order):
  35.  
  36.     1) The X coordinate
  37.     2) The Y coordinate
  38.     3) The 13th image from the resource bank, which is a button.
  39.  
  40.     It is important to note that when using images from the resource
  41.     bank for gadgets, you need to know their exact dimensions.  The
  42.     button we unpacked earlier is 64 pixels wide and 16 pixels high.
  43.     With this information you can set up a zone which fits the image
  44.     perfectly.
  45.  
  46.     Now is the time to actually see the resource bank, so load AMOS
  47.     Professional if it isn't already and select 'Resource Ed.' from
  48.     the 'User' menu.  When the resource bank creator has loaded,
  49.     click on the 'Load a bank' button.  Select the APSystem folder
  50.     and double click on the file 'AMOSPro_Default_Resource.Abk'.
  51.     When it has loaded you should see a screen full of different
  52.     buttons.  Click on 'Edit Graphic Elements'.  A button on the
  53.     screen should now flash and element number 1 should be 
  54.     highlighted in a selection box on the control panel.  Element
  55.     number 1 is the image we used to draw the 3d box in part1.  If
  56.     you click on different elements in the requester, different
  57.     buttons will flash.  If you drag the slider bar down, the list of
  58.     elements will scroll up or down.  If you click on element 13 then
  59.     the button which you used earlier will flash.  Take note of it's
  60.     dimensions, 64 * 16.  Exactly what we used before.  If you click
  61.     on element 14, the clicked button is highlighted.  If you want to
  62.     find the dimensions of a button, you use this requester.  Now
  63.     click on exit and then on quit.
  64.  
  65.     Load the file 'Interface_Example2.AMOS' into the editor now and
  66.     run it.  Impressive eh?  Now study the source code.  You will
  67.     notice that there are two new interface commands in that last
  68.     listing.  Namely BUtton and ButtonQuit (or BQ).  The BUtton
  69.     command takes the following parameters:
  70. @3
  71.     BU Identification number,X,Y,width,height,initial setting,
  72.        minimum,maximum;[][]
  73. @4
  74.     Most of the parameters are self-explanatory.  The Initial setting
  75.     is the button before it is clicked.  The minimum value is the
  76.     very least value the button can take and the maximum value is the
  77.     maximum value the button can take.  When the value reaches the
  78.     maximum value, it is reset to it's minimum value.  See the
  79.     explanation in the source code.  The first set of square brackets
  80.     should contain instructions that are to be executed when the
  81.     button is first drawn.  The second set of square brackets contain
  82.     instructions that are executed when the button is clicked.  In
  83.     the example, the clicked image of a button is unpacked to the
  84.     screen.  When the button is clicked, the image on the screen is
  85.     replaced with the clicked image therefore giving the impression
  86.     of depth.  The ButtonQuit command forces an exit from the 
  87.     interface program as soon as the button is clicked.
  88.     
  89.     The interface program is complete, all thats needed now is a loop 
  90.     which waits for a button click.  A function called Dialog is used 
  91.     to read the interface channel.  It is used like this:
  92. @3
  93.     BUTTON=Dialog(1)
  94. @4
  95.     The identification number of the button clicked is returned to
  96.     the BUTTON variable.  With this in mind you can branch to some
  97.     part of your program depending upon what value is contained 
  98.     within the variable.  The 1 in the brackets is simply the 
  99.     interface channel.  Now we have the command to read the interface 
  100.     program, you need a loop which will continue looping until some 
  101.     value is returned into BUTTON.  If no button is clicked the value 
  102.     of zero remains in the variable.  Look at the end of the listing 
  103.     for the loop to achieve this.
  104.  
  105.     This simple routine can be used to display error messages for
  106.     example.  The only problem is that the dialogue box will destroy
  107.     any background graphics beneath it.  So two commands are provided
  108.     called SIze and SAve.  SIze is used after a BAse command and it
  109.     expects two parameters.  The width and height of the box.  This
  110.     is needed so that the entire graphic under the box will be saved.
  111.     Afterwards, you need to actually save the image data.  SAve only
  112.     requires one parameter which is an indentification number.  Now
  113.     load 'Interface_Example3.AMOS' and run it.  You will notice that
  114.     when the button is clicked this time, the dialogue box is removed
  115.     from the screen, just what we want.  Decrease the values after
  116.     the SIze command.  Notice that some of the box is left behind.
  117.     The last example is a basis for a very useable message box, all
  118.     it needs is to be put in a procedure, then you can use it
  119.     anywhere.@4
  120.  
  121.     Load the file 'Interface_Example4.AMOS' and run it.  You are
  122.     invited to choose the best computer!!!  Choose correctly, you may
  123.     be electricuted!!!!!  The new interface command in this listing
  124.     is ButtonReturn (or BR) and it expects 1 parameter.  BR will
  125.     force the button to a different state as stated by the parameter.
  126.     Look at the explanation in the source code for more detail.
  127.     Believe it or not, that last example is the basis for a real
  128.     requester with several buttons!
  129.  
  130.